import React, { Component } from 'react'
class MyForm extends Component {
    constructor(props) {
        super(props)
        this.state = {
            name: '123',
            phone: '123'
        }
    }
    componentDidUpdate(prevProps, prevState) {
        if(prevState.name != this.state.name || prevState.phone != this.state.phone) {
            console.log('触发')
            this.props.saveData(this.state)
        }
    }
    render() {
        return <div className="my-form">
                    <h3>{this.props.title}</h3>
                    <form action="#">
                        <div>
                            <label>姓名：</label>
                            <input value={this.state.name} onChange={ev => this.setState({name: ev.target.value})}></input>
                        </div>
                        <div>
                            <label>手机号：</label>
                            <input value={this.state.phone}  onChange={ev => this.setState({phone: ev.target.value})}></input>
                        </div>
                    </form>
                </div>
    }
    getSnapshotBeforeUpdate(prevProps, prevState) {
        console.log(123, prevProps, prevState)
        return true
    }
}
MyForm.defaultProps = {
    title: '寄方信息'
}
export default MyForm